﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

///<summary>
///
///</summary>
public class BalloonInputKeyComponent : MonoBehaviour
{
    public  BalloonType curType;
	public KeyCode keyCode = KeyCode.LeftArrow;
	bool burst = false;
	public Sprite sprite;
    private void Awake()
    {
        DontDestroyOnLoad(gameObject);
        Debug.Log("加入不可销毁" + gameObject.name);
    }

    private void OnEnable()
	{
		burst = false;
		gameObject.transform.GetChild(0).gameObject.SetActive(true);
		gameObject.GetComponent<Image>().sprite = sprite;
	}
	
	public void CheckKey(KeyCode key)
	{
		if (Camera.main.ScreenToWorldPoint(transform.position).y > 5.3f)
			return;
		if (key == keyCode)
		{
			if (burst == false)
			{
                Break();
            }
		}
	}
	
	public void ChildrenHide()
	{
        AudioManager.GetInstance.Play("Sounds/balloon/balloon_explosion1");
		gameObject.transform.GetChild(0).gameObject.SetActive(false);
	}
	public BalloonType GetBalloonType()
	{
		return curType;
	}
	public void Break()
	{
		if (Camera.main.ScreenToWorldPoint(transform.position).y > 5.3f)
			return;
        ChildrenHide();
        burst = true;
        GetComponent<BalloonAnimationComponent>().PlayAnimation(0.03f);
	}
	public void LightningBreak()
	{
		ChildrenHide();
		GetComponent<BalloonAnimationComponent>().PlayAnimation(0.03f);
	}

	private void Update()
	{
		if (Input.GetKeyDown(KeyCode.Q))
		{
            if (burst == false)
            {
                Break();
            }
		}
	}
    public void RestGame()
    {
        gameObject.transform.SetParent(BalloonFactory.Instance.transform);
        gameObject.SetActive(false);
    }

    private void OnDestroy()
    {
        Debug.Log("被销毁" + "气球名：" + gameObject.name);
    }
}
